package org.zebra.logging.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import sun.misc.Unsafe;

import java.lang.reflect.Field;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
/**
 * @author zhanghongbin
 */
public class LoggingPrintUtil {

    /**
     * 屏蔽反射告警输出
     */
    public static final void hideReflectionWarnPrint() {
        try {
            // 通过 Unsafe 类禁用非法反射日志输出
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            Unsafe u = (Unsafe) theUnsafe.get(null);
            Class<?> cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
            Field logger = cls.getDeclaredField("logger");
            u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
        } catch (Exception ignored) {
        }
    }
}
